/********************************************************************
	created:	2012/02/26   23:21
	filename: 	hy_error.h
	author:		supercaco@sina.com
	purpose:	
*********************************************************************/
#ifndef _HY_ERROR_H_
#define _HY_ERROR_H_

//assert define
#include <cassert>
#define hy_assert assert

#define assert_ret(condition, tips, ret) \
{\
	if (!(condition))\
{\
	std::cerr << "????????????????????????????????????????????????????????????????????????????????" << endl;\
	std::cerr << "(error)" << tips << endl;\
	return ret;\
}\
}

#define assert_tip(condition, tips) \
{\
	if (!(condition))\
{\
	std::cerr << "????????????????????????????????????????????????????????????????????????????????" << endl;\
	std::cerr << "(error)" << tips << endl;\
}\
}


#include <errno.h>

#ifdef _WIN32
	#include <windows.h>
#endif


//error type
typedef int hy_err_t ;

//right status
const hy_err_t hy_right = 0;

//common error
const hy_err_t hy_error = -1;

inline bool is_right(hy_err_t ec)
{
	return hy_right == ec;
}

inline bool is_error(hy_err_t ec)
{
	return hy_right != ec;
}

inline void error(hy_i32_t err)
{
#ifdef _WIN32
	::WSASetLastError((DWORD)err);
#else
	errno = err;
#endif
}

inline hy_err_t error()
{
#ifdef _WIN32
	return ::WSAGetLastError();
#else
	return errno;
#endif
}

inline hy_err_t check_err(int err)
{
	return (err == HY_OS_ERROR) ?  error() : hy_right;
}



//////////////////////////////////////////////////////////////////////////
//error code
#ifdef _WIN32
	#define make_error_code(x) WSA##x
#else
	#define make_error_code(x) x
#endif


#endif //_HY_ERROR_H_
